<?php
namespace Admin\Controller;
use Think\Controller;
class PublicController extends Controller {
    // 用户登录页
    public function login(){
        $this->display();
    }

    // 验证用户登录
    public function checklogin(){
    	$model = M("AdminUser");
    	
    	$map['username'] = $_POST['username'];
    	$map['password'] = md5($_POST['password']);
    	$vo = $model->where($map)->find();

    	if($vo){
            session("admin_id", $vo['uid']);
            session("username", $vo['username']);
            // session("headimgurl", $vo['headimgurl']);

            $this->success("登录成功！", U("index.php/Tongcheng/Index/index"));
    	}else{
    		$this->error("你输入的信息有误！");
    	}
    }

    // 退出登录
    public function logout(){
        session(null);
        $this->success('退出登录成功！',"login");
    }


    public function upload(){
        $upload = new \Think\Upload();// 实例化上传类
        $upload->maxSize   =     3145728 ;// 设置附件上传大小
        $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
        $upload->rootPath  =      './Uploads/'; // 设置附件上传根目录
        $upload->savePath  =      ''; // 设置附件上传（子）目录
        // 上传文件 
        $info   =   $upload->upload();
        if(!$info) {// 上传错误提示错误信息
            $arr = array("err_code"=>400,"err_msg"=>$upload->getError());
            $this->ajaxReturn($arr);
        }else{// 上传成功 获取上传文件信息
            $file = $info['file'];
            $arr = array("err_code"=>0,"file_name"=>$file['savepath'].$file['savename']);
            $this->ajaxReturn($arr);
        }
    }
}